// ImageProcMatlabApp.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>
#include <iostream>
#include "engine.h"


int _tmain(int argc, _TCHAR* argv[])
{	
	std::cout << "***Matlab PoC App v1.0 by Yuchen Wang***" << std::endl;

	Engine *ep;
	mxArray *I = NULL;
	double current[10] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
	 
	if (!(ep = engOpen("\0")))
	{
		std::cerr << "Can't start MATLAB engine" << std::endl;
		return EXIT_FAILURE;
	}
	I = mxCreateDoubleMatrix(1, 10, mxREAL);						// create the variable I
	memcpy((void *)mxGetPr(I), (void *)current, sizeof(current));	// copy array to I
	engPutVariable(ep, "I", I);									// Place the variable I into the MATLAB workspace
	engEvalString(ep, "V = I.*10;");								// Plot the result
	engEvalString(ep, "plot(I,V);");
	engEvalString(ep, "title('Velocity vs. Current plot for a 10 ohm resistor');");
	engEvalString(ep, "xlabel('Current(amps)')");
	engEvalString(ep, "ylabel('Velocity(volts)');");
	std::string s;
	std::cout << "Type something to quit" << std::endl;
	std::getline(std::cin, s);                                // pause long enough to be able to see the plot
	mxDestroyArray(I);                              // return memory
	engEvalString(ep, "close;");					 // close MATLAB figure.
	std::cout << "Program exited successfully" << std::endl;
	return 0;
}

